<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${basePath}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图书馆管理系统欢迎您</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/quick-dialog/jquery.quick-dialog.js"></script>
<script type="text/javascript" src="js/jQueryAlert/src/jquery.alert.js"></script>
<link type="text/css" rel="stylesheet" href="js/jQueryAlert/src/jquery.alert.default.css"/>
<link rel="stylesheet" type="text/css" href="js/quick-dialog/jquery.quick-dialog.default.css">
<style type="text/css">

html, body {
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	text-align: center;
	font-family: 微软雅黑;
	font-size: 13px;
}
.backgroundDiv { position: fixed; width: 100%; height: 100%; z-index: -1; }
.backgroundDiv img { width: 100%; height: 100%;}

.contentDiv {
	width: 960px;
	margin: 0 auto;
}
.contentDiv .userDiv {
	color: white;
	text-align: right;
}
.contentDiv .userDiv a {
	color: black;
}

.contentDiv .searchDiv {
	background-color: rgba(255, 255, 255, 0.7);
	padding: 10px;
	border-style:solid;
	border-color: black;
}
.contentDiv .searchDiv label {
	display: inline-block;
	width: 100px;
	text-align: right;
}
.contentDiv .searchDiv input, .contentDiv .searchDiv select {
	width: 150px;
}

.contentDiv .searchDiv .buttonGroup input{
	style="cursor:pointer"
	width: 100px;
}
.contentDiv .resultDiv{
	background-color: rgba(255, 255, 255, 0.5);
	padding: 10px;
}
table {
	border: 0px silver solid; 
	margin-top: 20px;
	width: 100%;
}
table tr {
	height: 25	px;
	border: 1px silver solid;
	border-color: blue;
}
table tr th, table tr td {
	border: 1px silver solid;
	border-color: blue;
}

#DialogOut, #Dialogin,#updataPassWordDiv {
	width: 300px;
	height: 130px;
}

.OpenDialogOut, .OpenDialogin ,.updataPassWord{
	cursor: pointer;
}
#DialogOut label,#Dialogin label{
	width: 80px;
	text-align: right;
}
#DialogOut input,#Dialogin input {
	text-align: left;
}
.button3 {
	width: 100px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
	$("table tr:nth-child(even)").addClass("even");
	$("#DialogOut").dialog({
		trigger: ".OpenDialogOut",
		title: "借阅图书"
	});
	$(".OpenDialogOut").each(function(){
		$(this).click(function(){
			$("#outBookNo").val($(this).attr("id"));
		});
	});
	$("#Dialogin").dialog({
		trigger: ".OpenDialogin",
		title: "归还图书"
	});
	$(".OpenDialogin").each(function(){
		$(this).click(function(){
			$("#inBookNo").val($(this).attr("id"));
		});
	});
	$("#updataPassWordDiv").dialog({
		trigger: ".updataPassWord",
		title: "修改密码"
	});
});

$(document).ready(function() {
	$("#updataPassWordForm").submit(function() {
		if ($("#passWordAgain").val() != $("#upPassWord").val()) {
			if (!$("#passWordAgain").next().hasClass("error"))
				$("#passWordAgain").after("<a class='error' style='color: red;'>两次输入不一样</a>");
			return false;
		} else {
			$("#passWordAgain").next(".error").remove();
		}
	});
	console.log(1);
	$("#submit").click(function(){
		if ($("#upPassWord").val().length <= 0) {
			$.error("原始密码不能为空！");
			return false;
		} else if ($("#newPassWord").val().length <= 0) {
			$.error("新密码不能为空！");
			return false;
		} else if ($("#newPassWord").val() != $("#passWordAgain").val()) {
			$.error("俩次输入的密码不一样！");
			return false;
		} 
		$.ajax({
			type : "post",
			url : "user/updatePassword",
			data : "user.userName=" + $("#upUserName").val()
					+ "&user.passWord=" + $("#upPassWord").val()
					+ "&userDTO.newPassWord=" + $("#newPassWord").val(),
			dataType : "text",
			success : function(updateMsg){
				if(updateMsg == "updateFailed"){
					$.error("原始密码输入有误！");
				}else{
					$(".quick-dialog-default-close").click();
					$.alert("密码修改成功！");
				}
			}
		});
	});
});


</script>
</head>
<body>
	<div class="backgroundDiv">
		<img src="/picture/back5.jpg"/>
	</div>
	
	<div class="contentDiv">
		<div class="userDiv">
			<a>欢迎您：${user_Login.userName} </a><a class="updataPassWord">修改密码 </a><a href="user/User_out">安全退出</a>
		</div>
		<div class="searchDiv">
			<form action=book/Book_find method="post">
				<p>
					<label for="bookName">书名：</label>
					<input id="bookName" name="queryRestrictionsDTO.bookName" class="inputText" type="text"/>
					<label for="bookNumber">书号：</label>
					<input id="bookNumber" name="queryRestrictionsDTO.bookNumber" class="inputText" type="text">
				</p>
				<p>
					<label for="bookType">书籍类别：</label>
					<select id="bookType" name="queryRestrictionsDTO.bookType">
						 <option value="0" selected="selected"></option>
						 <option value="1">计算机</option>
					 	 <option value="2">数据库</option>		
					     <option value="3">生活常识</option>
					</select>
					<label for="author">作者：</label>
					<input id="author" name="queryRestrictionsDTO.author">
				</p>
				<p class="buttonGroup">
					<input class="button1" type="submit" value="查询" style="cursor:pointer" />
					<input class="button2" type="reset" value="重置" style="cursor:pointer"/>
					<s:if test="#session.user_Login.power == 0">
						<a href = "findRecord.jsp">查询借还，书记录</a>
					</s:if>
				</p>
			</form>
		</div>
		<div class="resultDiv">
		<s:if test="result != null"><script>$.alert("${ result }");</script></s:if>
			<table style="border-collapse: collapse;">
				<tr>
					<th style="width: 5%">书号</th>
					<th style="width: 10%">书名</th>
					<th style="width: 10%">类型</th>
					<th style="width: 10%">作者</th>
					<th style="width: 45%">简介</th>
					<th style="width: 10%">余量</th>
					<s:if test="#session.user_Login.power == 0"><th style="width: 10%">操作</th></s:if>
					
				
				</tr>
				<s:if test="books != null">
				<s:iterator value="books" var="book" >
				<tr class="even">
					<td><s:property value="#book.bookNo"/></td>
					<td><s:property value="#book.bookName"/></td>
					<s:if test="#book.bookType == 1"><td>计算机</td></s:if>
					<s:if test="#book.bookType == 2"><td>数据库</td></s:if>
					<s:if test="#book.bookType == 3"><td>生活常识</td></s:if>
					<td><s:property value="#book.author"/></td>
					<td><s:property value="#book.subScript"/></td>
					<s:if test="#book.count == 0"><td style="color:red">0</td></s:if>
					<s:else><td><s:property value="#book.count"/></td></s:else>
					<s:if test="#session.user_Login.power == 0">
					<td>
						<a class="OpenDialogOut" id="<s:property value="#book.bookNo"/>">借出</a>
						<a class="OpenDialogin" id="<s:property value="#book.bookNo"/>">归还</a>
						<!--<a href="book/Book_update?book.bookId=${book.bookId}&book.count=-1">借出</a>
						<a href="book/Book_update?book.bookId=${book.bookId}&book.count=1">归还</a>
					-->
					<s:if test="noBook == true">
					<script>alert("没有查询到图书！");</script>
					</s:if>
					<s:if test="msg == true">
					<script>alert("图书没有余量，不能借出！")</script>
					</s:if>
					</td>
					</s:if>
				</tr>
				</s:iterator>		
				</s:if>
<%-- 				<s:if test="noBook == true">
				<script>alert("没有查询到图书！");</script>
				</s:if>
				<s:if test="msg == \"true\"">
				<script>alert("图书没有余量，不能借出！")</script>
				</s:if> --%>
			</table>
			<s:if test="pageDTO != null">
			<s:iterator begin="0" end="pageDTO.pageCount / pageDTO.pageSize" var="i">
			<a href="book/Book_find?pageDTO.currentPage=${i}&queryRestrictionsDTO.bookName=${queryRestrictionsDTO.bookName}&queryRestrictionsDTO.bookNumber=${queryRestrictionsDTO.bookNumber}&queryRestrictionsDTO.bookType=${queryRestrictionsDTO.bookType}&queryRestrictionsDTO.author${queryRestrictionsDTO.author}"><s:property value="#i+1"/></a>
			</s:iterator>
			</s:if>
		</div>
	</div>
	
	<div id="DialogOut">
		<form action="record/Record_save">
			<label for="outUserName">借书人账号：</label>
			<input id="outUserName" name="record.user.userName" type="text" required="required"/><br>
			<label for="outBookNo">所借书籍号：</label>
			<input id="outBookNo" name="record.book.bookNo" type="text" required="required" /><br>
			<label for="outAmount">所借书数量：</label>
			<input id="outAmount" name="record.amount" type="text" required="required"/><br>
			<input type="submit" value="保存"/>
			<input type="reset" value="重置"/>
		</form>
	</div>
	
	<div id="Dialogin">
		<form action="record/Record_savein">
			<label for="inUserName">还书人账号：</label>
			<input id="inUserName" name="record.user.userName" type="text" required="required"/><br>
			<label for="inBookNo">所还书籍号：</label>
			<input id="inBookNo" name="record.book.bookNo" type="text" required="required" /><br>
			<label for="inAmount">所还书数量：</label>
			<input id="inAmount" name="record.amount" type="text" required="required"/><br>
			<input class="button3" type="submit" value="保存"/>
			<input class="button3" type="reset" value="重置"/>
		</form>
	</div>
	<div id="updataPassWordDiv">
		<form id="updataPassWordForm"action="user/User_updataPassWord">
			<label for="upUserName">登录帐号：</label>
			<input id="upUserName" name="user.userName" type="text" value="${ session.user_Login.userName }" required="required" readonly="readonly"/><br>
			<label for="upPassWord">原始密码：</label>
			<input id="upPassWord" name="user.passWord" type="text" required="required" /><br>
			<label for="newPassWord">新设密码：</label>
			<input id="newPassWord" name="userDTO.newPassWord" type="text" required="required"/><br>
			<label for="passWordAgain">密码确认：</label>
			<input id="passWordAgain" name="userDTO.passWordAgain" type="text" required="required"/><br>
			<input id="submit" class="button3" type="button" value="保存"/>
		</form>
	</div>
</body>
</html>